home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 1 / Macwelt DVD 1.toast / Web-Publishing / HTML-Editoren / Alpha ƒ / Mode Examples / SQL-Example.sql < prev    next >
Encoding:
Text File  |  2000-10-30  |  2.0 KB  |  77 lines

  1. -- SQL-Example.sql
  2. --
  3. -- source of original document:
  4. --
  5. -- <http://gserver.grads.vt.edu/>
  6.  
  7. -- PL/SQL utility package to access regex.
  8. -- created 13 sept 95 by tdunbar@gserver.grads.vt.edu
  9.  
  10. create or replace package regex as
  11.   function amatch(regex_i in varchar2, string_i in varchar2,
  12.                     timeout in number default 10) return number;
  13.   procedure match(regex_i in varchar2, string_i in varchar2);
  14.   procedure stop(timeout number default 10);
  15.  
  16. end regex;
  17. /
  18.  
  19. create or replace package body regex as
  20.  
  21.   procedure match(regex_i in varchar2, string_i in varchar2) is
  22.       i number;
  23.     begin
  24.       i:=amatch(regex_i,string_i);
  25.       htp.p('returns '||i);
  26.     end;
  27.  
  28.   function amatch(regex_i in varchar2, string_i in varchar2,  
  29.                      timeout in number default 10) return number is
  30.     s number;
  31.     result varchar2(20);
  32.     command_code number;
  33.     pipe_name varchar2(30);
  34.   begin
  35.     pipe_name := dbms_pipe.unique_session_name;
  36.     dbms_pipe.pack_message('AMATCH');
  37.     dbms_pipe.pack_message(pipe_name);
  38.     dbms_pipe.pack_message(regex_i);
  39.     dbms_pipe.pack_message(string_i);
  40.     s := dbms_pipe.send_message('amatch', timeout);
  41.     if s <> 0 then
  42.       raise_application_error(-20010,
  43.         'Execute_system: Error while sending.  Status = ' || s);
  44.     end if;
  45.  
  46.     s := dbms_pipe.receive_message(pipe_name, timeout);
  47.     if s <> 0 then
  48.       raise_application_error(-20011,
  49.         'Execute_system: Error while receiving.  Status = ' || s);
  50.     end if;
  51.  
  52.     dbms_pipe.unpack_message(result);
  53.     if result <> 'done' then
  54.       raise_application_error(-20012,
  55.         'Execute_system: Done not received.');
  56.     end if;
  57.  
  58.     dbms_pipe.unpack_message(command_code);
  59.     return command_code;
  60.   end amatch;
  61.  
  62.   procedure stop(timeout number default 10) is
  63.     s number;
  64.   begin
  65.  
  66.     dbms_pipe.pack_message('STOP');
  67.     s := dbms_pipe.send_message('amatch', timeout);
  68.     if s <> 0 then
  69.       raise_application_error(-20030,
  70.         'Stop: Error while sending.  Status = ' || s);
  71.     end if;
  72.   end stop;
  73.  
  74. end regex;
  75. /
  76. show errors;
  77.